package cn.itcast.mq.listener;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Map;

@Component
public class SpringRabbitListener {
    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
        System.out.println("spring接收到的消息是：" + msg+"___"+ LocalDateTime.now());
        Thread.sleep(20);
    }

    @RabbitListener(queues = "simple.queue")
    public void listenFanoutQueue1(String msg) throws InterruptedException {
        System.err.println("FanoutQueue1接收到的消息是：" + msg+"___"+ LocalDateTime.now());
        Thread.sleep(200);
    }


    @RabbitListener(queues = "fanout.queue1")
    public void listenFanoutQueue1QueueMessage(String msg) throws InterruptedException {
        System.out.println("fanout.queue1接收到的消息是：" + msg+"___"+ LocalDateTime.now());
    }

    @RabbitListener(queues = "fanout.queue2")
    public void listenFanoutQueue2QueueMessage(String msg) throws InterruptedException {
        System.out.println("fanout.queue2接收到的消息是：" + msg+"___"+ LocalDateTime.now());
    }

    @RabbitListener(queues = "obj.queue")
    public void listenObjQueueMessage( Map<String, Object> msg) throws InterruptedException {
        System.out.println("obj.queue接收到的消息是：" + msg);
    }
}
